package com.magic.gre.ui.dialog;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.TextView;

import com.magic.gre.R;
import com.magic.gre.adapter.MeanAdapter;
import com.magic.gre.base.dialog.BaseBottomDialog;
import com.magic.gre.entity.AnswerBean;

/**
 * Author: Lmoumou
 * Date: 2019-01-09 15:11
 * 文件名: WordsDetailsDialog
 * 描述:
 */
public class WordsDetailsDialog extends BaseBottomDialog {
    private AnswerBean answerBean;
    private RecyclerView mRecyclerView;
    @Override
    protected int setViewId() {
        return R.layout.dialog_words_details;
    }

    @Override
    protected Float setDialogWith() {
        return 0.9F;
    }

    @Override
    protected void initView(View view) {
        if (answerBean!=null){
            TextView wordsTv=view.findViewById(R.id.words_tv);
            wordsTv.setText(answerBean.getName());
            TextView pronunciationTv=view.findViewById(R.id.pronunciation_tv);
            pronunciationTv.setText(answerBean.getSymbol());
            mRecyclerView=view.findViewById(R.id.mRecyclerView);
            mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
            mRecyclerView.setAdapter(new MeanAdapter(mContext, answerBean.getMeanings()));
        }


        view.findViewById(R.id.close_iv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismissThis(isResumed());
            }
        });
    }

    @Override
    protected void initBundle(Bundle bundle) {

    }

    public void showThis(FragmentManager manager, String tag, AnswerBean answerBean) {
        super.showThis(manager, tag);
        this.answerBean=answerBean;
    }

    @Override
    public void onResume() {
        super.onResume();
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        getDialog().getWindow().setLayout((int) (dm.widthPixels * setDialogWith()), (int) (dm.heightPixels * 0.8));
    }


}
